﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Things.Common;
using LTP.Accounts.Bus;
namespace Things.ThingsWeb.BuyerInfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    string BuyerAccount = Request.Params["id"];
                    ShowInfo(BuyerAccount);
                }
            }
        }

        private void ShowInfo(string BuyerAccount)
        {
            Things.BLL.BuyerInfo bll = new Things.BLL.BuyerInfo();
            Things.Model.BuyerInfo model = bll.GetModel(BuyerAccount);
            this.lblBuyerAccount.Text = model.BuyerAccount;
            this.txtPetName.Text = model.PetName;
            this.txtRealName.Text = model.RealName;
            this.txtEmail.Text = model.Email;
            this.txtMobilePhone.Text = model.MobilePhone;
            this.txtAddress.Text = model.Address;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtPetName.Text.Trim().Length == 0)
            {
                strErr += "昵称不能为空！\\n";
            }
            if (this.txtRealName.Text.Trim().Length == 0)
            {
                strErr += "真实姓名不能为空！\\n";
            }
            if (this.txtEmail.Text.Trim().Length == 0)
            {
                strErr += "Email邮箱不能为空！\\n";
            }
            if (this.txtMobilePhone.Text.Trim().Length == 0)
            {
                strErr += "手机号不能为空！\\n";
            }
            if (this.txtAddress.Text.Trim().Length == 0)
            {
                strErr += "地址不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string BuyerAccount = this.lblBuyerAccount.Text;
            string PetName = this.txtPetName.Text;
            string RealName = this.txtRealName.Text;
            string Email = this.txtEmail.Text;
            string MobilePhone = this.txtMobilePhone.Text;
            string Address = this.txtAddress.Text;


            Things.Model.BuyerInfo model = new Things.Model.BuyerInfo();
            model.BuyerAccount = BuyerAccount;
            model.PetName = PetName;
            model.RealName = RealName;
            model.Email = Email;
            model.MobilePhone = MobilePhone;
            model.Address = Address;

            Things.BLL.BuyerInfo bll = new Things.BLL.BuyerInfo();
            bll.Update(model);
            Things.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
